#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <stdio.h>
#include <stdlib.h>

//共享内存读程序
int main (int argc, char **argv)
{
	int shm_id;
	int *ptr;

	if (-1 == (shm_id = shmget(12345, 4, 0666)))
	{
		perror("shmget");
		exit(-1);
	}

	if (NULL == (ptr = shmat(shm_id, NULL, 0)))
	{
		perror("shmat");
		exit(-1);
	}

	while(1)
	{
		printf("read num: %d\n", *ptr);
		sleep(2);
	}
}

